SHELL := guix time-machine --channels=guix-env/channels.scm -- shell --check --manifest=guix-env/manifest.scm -- bash -c
# .SHELLFLAGS = -Euxo pipefail -c
.SHELLFLAGS = -Euo pipefail -c

GUILE_LOAD_PATH := .
GUILE_LOAD_PATH += contracts
GUILE_LOAD_PATH += commands
GUILE_LOAD_PATH += test

GUILE_LOAD_PATH_ARG := $(foreach dir, $(GUILE_LOAD_PATH),-L $(dir))

GUILE_LOADED_FILES := shell.scm
GUILE_LOADED_FILES += commands.scm

GUILE_LOADED_FILES_ARG := $(foreach file, $(GUILE_LOADED_FILES),-l $(file))

TEST_MODULES := $(wildcard test/*.scm)


.DEFAULT: test

.PHONY: print-test-modules
print-test-modules:
	printf "%s\n" "$(TEST_MODULES)"


.PHONY: test
test:
	# Not using (foreach ...) here, to avoid very long commands.
	for module in $(TEST_MODULES) ; do \
		guile $(GUILE_LOAD_PATH_ARG) "$${module}" ; \
	done


.PHONY: shell
shell:
	guile $(GUILE_LOAD_PATH_ARG) $(GUILE_LOADED_FILES_ARG)
